home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / BitSet.C < prev    next >
C/C++ Source or Header  |  1992-05-05  |  1KB  |  75 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "BitSet.h"
  6.  
  7. #include "Class.h"
  8.  
  9. //---- BitSet ------------------------------------------------------------------
  10.  
  11. NewMetaImpl(BitSet,Object, (TX(m)));
  12.  
  13. int BitSet::Capacity()     
  14.     return sizeof(int)*8; 
  15. }
  16.  
  17. u_long BitSet::Hash() 
  18. {   
  19.     return m; 
  20. }
  21.     
  22. bool BitSet::IsEmpty()  
  23.     return m==0; 
  24. }
  25.     
  26. bool BitSet::IsEqual(Object* ob)
  27. {
  28.     return ob->IsKindOf(BitSet) && m == ((BitSet*)ob)->m;
  29. }
  30.  
  31. OStream& BitSet::PrintOn(OStream &s)
  32. {
  33.     Object::PrintOn(s);
  34.     return s << m SP;  
  35. }
  36.  
  37. IStream& BitSet::ReadFrom(IStream &s)
  38. {
  39.     long mm;
  40.     Object::ReadFrom(s);
  41.     s >> mm;
  42.     m= (u_long) mm;
  43.     return s;
  44. }
  45.  
  46. int BitSet::Size()
  47. {
  48.     register u_long l, n;
  49.  
  50.     for (l= m, n= 0; l != 0; n++)
  51.     l &= (l-1);     // removes rightmost 1 
  52.     return n;
  53. }
  54.  
  55. //---- class BitSetIter ----------------------------------------------------
  56.  
  57. void BitSetIter::Reset(BitSet *s)
  58. {
  59.     cb= s;
  60.     pos= 0;
  61. }
  62.     
  63. int BitSetIter::operator()()
  64. {
  65.     while (!cb->Includes(pos) && pos < cb->Capacity())
  66.     pos++;
  67.     if (pos == cb->Capacity())
  68.     return 0;
  69.     return pos++;
  70. }
  71.  
  72.  
  73.